package com.mao.stringdemo;

import java.util.Scanner;

public class StringDemo1 {
    public static void main(String[] args) {
        String s1 = "Hello, World";
        System.out.println(s1);
        System.out.println(s1.length());

        //2
        String s2 = new String();// 不推荐
        System.out.println(s2); // 空字符串

        String s3 = new String("Hello, Java");
        System.out.println(s3);

        char[] chars = {'a', 'b', 'c'};
        String s4 = new String(chars);
        System.out.println(s4);

        byte[] bytes = {97, 98, 99};
        String s5 = new String(bytes);
        System.out.println(s5);

        System.out.println("===========================");
        // 只有双引号“”给出的字符串对象放在字符串常量池，相同内容只放一份。
        String s6 = "Hello, World";
        String s7 = "Hello, World";
        System.out.println(s6 == s7);

        String s8 = new String("Hello, World");
        String s9 = new String("Hello, World");
        System.out.println(s8 == s9);

        System.out.println("===========================");
        String s10 = "Hello, Java";
        System.out.println(s10);
        // 将“hahahah”替换为“Hello, Java”使用replace
        String s11 = s10.replace(s10, s9);
        System.out.println(s11);

        System.out.println("===========================");
        // 调用字符串的方法，处理字符串数据
        // 登录
        String s12 = "admin";

        System.out.println("请输入登录账号");
        Scanner sc = new Scanner(System.in);
        String LoginName = sc.next();
        // 字符串对象的内容比较，不能用==，==默认比较地址，
        // 判断字符串内容用equals
//        if(LoginName == s12)
//            System.out.println("登录成功");
//        else
//            System.out.println("登录失败");
//
        if(LoginName.equals(s12))
            System.out.println("登录成功");
        else
            System.out.println("登录失败");
        System.out.println("===========================");


    }
}
